package com.validator;

import com.opensymphony.xwork2.validator.ValidationException;
import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;

public class IsCheckCodeRight extends FieldValidatorSupport {
	private String checkCode;
	private boolean trim = true;

	@Override
	public void validate(Object o) throws ValidationException {
		Object objValidateCode = getFieldValue(checkCode, o);
		String fieldName = getFieldName();
		String fieldValue = (String) getFieldValue(fieldName, o);
		
		if (fieldValue == null)
			return;
		if (trim)
			fieldValue = fieldValue.trim();
		if (fieldValue.length() == 0) {
			return;
		}
		if (!fieldValue.equals(objValidateCode)) {
			addFieldError(fieldName, o);
		}
	}
	
	public String getCheckCode() {
		return checkCode;
	}

	public void setCheckCode(String checkCode) {
		this.checkCode = checkCode;
	}
	
}
